package common

import "github.com/ning1875/inverted-index/labels"

type ResourceQueryReq struct {
	ResourceType string `json:"resource_type" binding:"required"` /// 资源类型
	// ResourceIds []int64 `json:"resource_ids" binding:"required"`  //要操作的资源id 列表
	Labels      []*SingleTagReq `json:"labels" binding:"required"` //查询的标签组
	TargetLabel string          `json:"target_label" binding:"required"`
}

type SingleTagReq struct {
	Key   string `json:"key" binding:"required"`   //标签的名字
	Value string `json:"value" binding:"required"` //标签的值，可以是正则匹配
	Type  int    `json:"type" binding:"required"`  //标签类型1-4  =  != ~= ~!

}

func FormatLabelMatcher(ls []*SingleTagReq) []*labels.Matcher {
	matcher := make([]*labels.Matcher, 0)
	for _, l := range ls {
		mType, ok := labels.MatchMap[l.Type]
		if !ok {
			continue
		}
		matcher = append(matcher, labels.MustNewMatcher(mType, l.Key, l.Value))
	}
	return matcher

}
